package com.guit.hrms.controller;

import com.guit.hrms.dto.UpdateOnboardingStatusDTO;
import com.guit.hrms.po.utilsPO.PageBean;
import com.guit.hrms.po.utilsPO.Result;
import com.guit.hrms.service.OnboardingService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/api/onboarding")
public class OnboardingController {

    @Autowired
    private OnboardingService onboardingService;

    /**
     * 获取代办入职信息
     * @param page 当前页
     * @param pageSize 每页显示条数
     * @param onboardingTime 入职办理时间
     * @param onboardingPlace 入职办理地点
     * @return Result
     */
    @GetMapping
    public Result getOnboarding(@RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pageSize,
                                LocalDateTime onboardingTime, String onboardingPlace,
                                /*@RequestParam(defaultValue = "0")*/Integer status){

        PageBean pageBean =  onboardingService.getOnboarding(page,pageSize,onboardingTime,onboardingPlace, status);

        return Result.success(pageBean);
    }

    /**
     * 更新入职状态
     * @param updateOnboardingStatusDTO 更新入职状态DTO
     * @return Result
     */
    @PutMapping
    @Valid
    public Result updateOnboardingStatus(@Validated @RequestBody UpdateOnboardingStatusDTO updateOnboardingStatusDTO){
        if (updateOnboardingStatusDTO.getTryoutStartTime().isAfter(updateOnboardingStatusDTO.getTryoutEndTime())){
            return Result.error("试用期开始时间不能晚于结束时间");
        }
        return  Result.success(onboardingService.updateOnboardingStatus(updateOnboardingStatusDTO));
    }
}
